#include<iostream>
#include<cstring>
#include<algorithm>	
using namespace std;
const int N = 1010;
int arr[N];
int n;
bool cmp(int a, int b)
{
	return a > b;
}
int main()
{
	while (cin >> n) {
		if (n == 0) {
			break;
		}
		memset(arr, 0, sizeof(arr));
		for (int i = 0; i < n; i++) {
			cin >> arr[i];
		}
		sort(arr, arr + n, cmp);
		int money;
		cin >> money;
		if (money >= 5) {
			int ans = money;
			for (int i = 0; i < n && ans >= 5; i++) {
				ans -= arr[i];
			}
			cout << ans << endl;
		}
		else {
			cout << money << endl;
		}
	}
	return 0;
}